package cn.exrick.xboot.modules.quartz.jobs;

import cn.exrick.xboot.modules.Information.entity.Cross;
import cn.exrick.xboot.modules.Information.entity.CrossCheck;
import cn.exrick.xboot.modules.Information.service.ICrossCheckService;
import cn.exrick.xboot.modules.Information.service.ICrossService;
import cn.hutool.core.date.DateUtil;
import lombok.extern.slf4j.Slf4j;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.Date;
import java.util.List;


/**
 * 示例带参定时任务
 * @author Exrickx
 */
@Slf4j
public class QuartzCross implements Job {
    @Autowired
    private ICrossService iCrossService;

    @Autowired
    private ICrossCheckService iCrossCheckService;
    @Override
    public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {

        log.info(String.format("欢迎使用XBoot前后端分离开发平台!作者:Exrick 时间:"+ DateUtil.now()));
        List<Cross> list = iCrossService.list();
        for (Cross c:list) {
            CrossCheck crosscheck = new CrossCheck();
            crosscheck.setCreateTime(new Date());
            crosscheck.setWithDepartment(c.getWithDepartment());
            crosscheck.setRiverId(c.getRiverId());
            crosscheck.setCrossNum(c.getCrossNum());
            crosscheck.setCrossPlace(c.getCrossPlace());
            crosscheck.setStandardCod(c.getCod());
            crosscheck.setStandardNh3(c.getNh3());
            crosscheck.setStandardTp(c.getTp());
            iCrossCheckService.save(crosscheck);
        }

        log.info("定时查询考核"+String.valueOf(list.size()));
    }
}
